#ifndef F_TestSensorBiC_h
#define F_TestSensorBiC_h

// ***********************************************************************

// class EDROOMTopContext

// ***********************************************************************



class EDROOMTopContext {

protected:

enum EDROOMTestSensorBiSignal { EDROOMSignalTimeout, EDROOMSignalDestroy, SToListening, SToStandBy, SNextSensorSsiDataFrame, SDataFrame, SSignalFrame };


	friend class TestSensorBi;

	TestSensorBi &EDROOMcomponent;

	CEDROOMMessage * &Msg;

	CEDROOMMessage * &MsgBack;

	//Ports

	CEDROOMInterface & SsiCtrl;
	CEDROOMInterface & StoreAndNextFrame;

	enum edroomStateId{I, Listening};

	enum IdTrans{Init, StoreFrame, ReceiveAck, ReceiveNextSignal, ReceiveNextSignal_SendData, ReceiveNextSignal_SendAck,  EDROOMMEMORIA };

	//Constantes



	//Variables

	int &VMessageNumber;
	int &VMessageReceived;
	bool_t &VMoreData;
	CDFrame &VDataFrame;


	//Pool

	class CEDROOMPOOLCDFrame:public CEDROOMProtectedMemoryPool {
		public:
		CEDROOMPOOLCDFrame(TEDROOMUInt32 elemCount,CDFrame *pMem, bool_t *pMarks);
		CDFrame	* AllocData();
	};
	CEDROOMPOOLCDFrame	& CEDROOMPoolCDFrame;
	class CEDROOMPOOLCDSignal:public CEDROOMProtectedMemoryPool {
		public:
		CEDROOMPOOLCDSignal(TEDROOMUInt32 elemCount,CDSignal *pMem, bool_t *pMarks);
		CDSignal	* AllocData();
	};
	CEDROOMPOOLCDSignal	& EDROOMPoolCDSignal;


	// CONSTRUCTORES

	EDROOMTopContext (TestSensorBi &act, int & EDROOMpVarVMessageNumber, int & EDROOMpVarVMessageReceived, bool_t & EDROOMpVarVMoreData, CDFrame & EDROOMpVarVDataFrame, CEDROOMPOOLCDFrame & EDROOMpPoolCDFrame, CEDROOMPOOLCDSignal & EDROOMpPoolCDSignal );

	EDROOMTopContext ( EDROOMTopContext &contex );

public:

	bool EDROOMSearchContextTrans(TEDROOMTransId &edroomCurrentTrans);

	void EDROOMNuevoMens () { EDROOMcomponent.EDROOMNewMsg(); }

	// Funciones Definidas por el usuario

	bool_t	FGetFrames(TEDROOMInt32 numFile,byte_t *message);

	void	FInit();

	void	FIntToChar(TEDROOMInt32 num,byte_t * cConvert);

	void	FSendNextData();

	void	FStoreFrame();

	void	FCheckFiles();

	void	FStoreAck();

	void	FReceiveNextSignal();

	bool_t	GMoreData();

	void	FSendAck();

};

// ***********************************************************************

// class EDROOMTopState

// ***********************************************************************



class EDROOMTopState : public EDROOMTopContext {

protected:



	EDROOMTopContext::edroomStateId edroomCurrentState;

	EDROOMTopContext::edroomStateId edroomNextState;

	//Variables

	int VMessageNumber;
	int VMessageReceived;
	bool_t VMoreData;
	CDFrame VDataFrame;


	//Pools

	CEDROOMPOOLCDFrame	CEDROOMPoolCDFrame;
	CEDROOMPOOLCDSignal	EDROOMPoolCDSignal;


public:

	// CONSTRUCTOR

	EDROOMTopState (TestSensorBi &act, CEDROOMMemory *pEDROOMMemory  );


	// EDROOMBehaviour**********************************************

	void EDROOMBehaviour();

	// Inicio**********************************************

	void EDROOMInicio();

	// ***********************************************************************

	// SubEstado Inicial 

	// ***********************************************************************



	TEDROOMTransId EDROOMIllegada();

	// ***********************************************************************

	// SubEstado Hoja Listening

	// ***********************************************************************



	TEDROOMTransId EDROOMListeningllegada();

};


#endif
